package com.yanqu.road.server.manger.config;

import com.yanqu.road.entity.config.inn.DishesInfo;
import com.yanqu.road.logic.bussiness.config.DishesBussiness;
import com.yanqu.road.server.TempMgr;
import com.yanqu.road.server.manger.ConfigMgr;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;


//菜品信息
public class DishesMgr extends TempMgr {

    //菜品id   菜品信息
    private static Map<Integer, DishesInfo> dishesInfoMap;
    //菜品类型      菜品id    菜品信息
    private static Map<Integer, Map<Integer, DishesInfo>> dishesInfoTypeMap;

    @Override
    public boolean reloadConfig() throws Exception {
        dishesInfoMap = DishesBussiness.getDishesInfoMap();
        dishesInfoTypeMap = new ConcurrentHashMap<>();

        if (null == dishesInfoMap || dishesInfoMap.size() <= 0) {
            return true;
        }

        for (DishesInfo dishesInfo : dishesInfoMap.values()) {
            int type = dishesInfo.getDishesType();
            if (!dishesInfoTypeMap.containsKey(type)) {
                dishesInfoTypeMap.put(type, new HashMap<>());
            }
            dishesInfoTypeMap.get(type).put(dishesInfo.getDishesId(), dishesInfo);
        }

        return true;
    }

    @Override
    public boolean reloadData() throws Exception {
        return true;
    }


    @Override
    public boolean init() throws Exception {
        return reload();
    }

    @Override
    public boolean stop() {
        return false;
    }


    public static Map<Integer, Integer> getHootDishes(int weekIndex) {
        return ConfigMgr.getHootDishesTypeMap().get(weekIndex);
    }

    public static DishesInfo getDishes(int dishesId) {
        return dishesInfoMap.get(dishesId);
    }

    //当前1对多 关系
    public static List<Integer> getOccupationByDishesType(int dishesType) {
        Map<Integer, List<Integer>> dishesOccupationMap = ConfigMgr.getDishesOccupationMap();
        if (null != dishesOccupationMap) {
            return ConfigMgr.getDishesOccupationMap().get(dishesType);
        }
        return new ArrayList<>();
    }

}
